package com.operate.api.operate.opinion.service.impl;

import cn.hutool.core.util.DesensitizedUtil;
import com.operate.api.base.Constants;
import com.operate.api.base.Type;
import com.operate.api.operate.banner.domain.po.BannerPO;
import com.operate.api.operate.opinion.dao.OpinionDao;
import com.operate.api.operate.opinion.domain.po.OpinionPO;
import com.operate.api.operate.opinion.domain.vo.OpinionAddVO;
import com.operate.api.operate.opinion.domain.vo.OpinionSearchVO;
import com.operate.api.operate.opinion.domain.vo.OpinionVO;
import com.operate.api.operate.opinion.service.IOpinionService;
import com.operate.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
@Slf4j
public class OpinionServiceImpl implements IOpinionService {

    @Autowired
    private OpinionDao dao;


    @Override
    public List<OpinionVO> getList(OpinionSearchVO searchVO) {
        List<OpinionVO> list = dao.getList(searchVO);
        if(list!=null&&list.size()>0){
            for (OpinionVO opinionVO:list){
                opinionVO.setUserPhone(DesensitizedUtil.mobilePhone(opinionVO.getUserPhone()));
            }
        }
        return list;
    }

    @Override
    public void add(OpinionAddVO vo) {
        OpinionPO po = new OpinionPO();
        BeanUtils.copyProperties(vo, po);
        po.preInsert();
        int i = dao.insertSelective(po);
        if (i == Constants.SQL_RETURN_SUCCESS) {
            throw new BusinessException(Type.FAIL);
        }
    }
}